{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    3042.8232\n",
       "Name: price, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Streaming of real time data using tushare\n",
    "\n",
    "import tushare as ts\n",
    "\n",
    "# ts.get_today_all()\n",
    "\n",
    "shdata = ts.get_realtime_quotes('sh')\n",
    "\n",
    "shdata['price']\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "import time\n",
    "from random import shuffle\n",
    "from bokeh.plotting import figure, output_server, cursession, show\n",
    "\n",
    "# prepare output to server\n",
    "output_server(\"animated_line\")\n",
    "\n",
    "p = figure(plot_width=400, plot_height=400)\n",
    "p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], name='ex_line')\n",
    "show(p)\n",
    "\n",
    "# create some simple animation..\n",
    "# first get our figure example data source\n",
    "renderer = p.select(dict(name=\"ex_line\"))\n",
    "ds = renderer[0].data_source\n",
    "\n",
    "while True:\n",
    "    # Update y data of the source object\n",
    "    shuffle(ds.data[\"y\"])\n",
    "\n",
    "    # store the updated source on the server\n",
    "    cursession().store_objects(ds)\n",
    "    time.sleep(0.5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
